package com.lanswon.common.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

import org.springframework.util.Base64Utils;

public class TokenProccessor {
	private TokenProccessor() {
	};

	private static final TokenProccessor instance = new TokenProccessor();

	public static TokenProccessor getInstance() {
		return instance;
	}

	/**
	 * 生成Token
	 * 
	 * @return
	 */
	public String makeToken() {
		String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";
		try {
			MessageDigest md = MessageDigest.getInstance("md5");
			byte md5[] = md.digest(token.getBytes());
			// BASe64 encoder = new BASE64Encoder();
			String encodeToString = Base64Utils.encodeToString(md5);
			return encodeToString;
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		String token = TokenProccessor.getInstance().makeToken();
		System.out.println(token);
	}
	
	private String createToken() {
		// 加载
		//PropertiesUtils.load("/config/system.properties");
		//String prefix  = PropertiesUtils.get("token");
		
		return TokenProccessor.getInstance().makeToken();
	}
}
